#include "test.pb.h"

#include <iostream>
#include <string>

using namespace std;
using namespace fixbug;

void func1()
{
    // 封装 login 请求的对象的数据
    LoginRequest req;
    req.set_name("FFF");
    req.set_pwd("fff");

    // 序列化
    string send_str;
    if(req.SerializeToString(&send_str))
    {
        // 序列化成功
        cout << send_str << endl;
    }

    // 从 send_str 反序列化
    LoginRequest reqb;
    if(reqb.ParseFromString(send_str))
    {
        // 反序列化成功
        cout << reqb.name() << endl;
        cout << reqb.pwd() << endl;
    }
}

void func2()  // 处理列表 demo
{
    LoginResponse rsp;
    ResultCode *rc = rsp.mutable_result();
    rc->set_errcode(1);
    rc->set_errmsg("登录处理失败");

    GetFriendListsResponse rsp2;
    ResultCode *rc2 = rsp2.mutable_result();
    rc->set_errcode(0);

    User *user1 = rsp2.add_friend_list();
    user1->set_name("FFF");
    user1->set_age(24);
    user1->set_sex(User::WOMAN);

    cout << rsp2.friend_list_size() << endl;
}

int main()
{
    func2();

    return 0;
}